package com.longy.gulimall.product.mq;

import org.apache.activemq.command.ActiveMQTextMessage;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Topic;

@Component
public class MessageSender {
    @Resource
    private JmsTemplate jmsTemplate;

    @Resource(name = "devQueue")
    private Queue queue;

    @Resource
    private Topic topic;

    public void sendMsg(String msg) {
        System.out.println("发送消息内容 :" + msg);
        this.jmsTemplate.convertAndSend(this.queue, msg);
    }

    public void sendTopicMsg(Object msg) {
        System.out.println("发送消息内容 :" + msg);
        this.jmsTemplate.convertAndSend(this.topic, msg);
    }

    public void sendMsg(String queue,Object msg) {
        System.out.println("发送消息内容 :" + msg);
        this.jmsTemplate.convertAndSend(queue, msg);
    }
}
